﻿import storm
import storm.locals as sl


#class Person:  # 这样不行
class Person(object):
    __storm_table__ = 'person'
    id = sl.Int(primary=True)
    name = sl.Unicode()
    
    def __init__(self, name=None):
        self.name = name
        
def main():
    mysql = sl.create_database('mysql://root:@localhost/test')
    st = sl.Store(mysql)
    
    p1 = Person()
    p1.name = u'中文'
    
    st.add(p1)
    p2 = st.find(Person, Person.name==u'中文')
    print p2[0].name
    
    p2 = st.get(Person, 1)
    st.flush()
    
    p3 = st.find(Person,
        ((Person.id>=7) | (Person.id<=10) & (Person.id>=16) | (Person.id<=18)),
        #((Person.id>=7) or (Person.id<=10) and (Person.id>=16) or (Person.id<=18)),
        Person.name.like(u'中%'))
    print p3.count()
    print [(x.id, x.name) for x in p3]
    
if __name__ == '__main__':
    main()